//
//  DetailInformationViewController.m
//  Frame
//
//  Created by 这是工作本 on 16/2/22.
//  Copyright © 2016年 这是工作本. All rights reserved.
//

#import "DetailInformationViewController.h"

@interface DetailInformationViewController () <UIGestureRecognizerDelegate, UITextFieldDelegate>
@property (nonatomic, retain) UITextField *comment;
@property (nonatomic, retain) UIButton *send;
@property (nonatomic, retain) UIButton *like;
@end

@implementation DetailInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"资讯详情";
    //隐藏自动返回
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29 / 255.0 green:127 / 255.0  blue:140 / 255.0  alpha:1.0];
    
    //返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"but_an.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonAction:)];
    
    //设置title颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0],NSForegroundColorAttributeName,nil]];
    //背景
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 45 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width , 45 * ScreenHeigth)];
    view.backgroundColor = [UIColor colorWithRed:250 / 255.0 green:250 / 255.0 blue:250 / 255.0 alpha:1.0];
    [self.view addSubview:view];
    
    //分享
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fxx.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(right)];
    
    //收藏
    self.like = [UIButton buttonWithType:UIButtonTypeCustom];
    self.like = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 75 * ScreenWidth, 12, 22 * ScreenWidth, 23 * ScreenHeigth)];
    [self.like setImage:[UIImage imageNamed:@"dzz.png"] forState:UIControlStateNormal];
    [self.like addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationController.navigationBar addSubview:self.like];

    
    //评论
    self.comment = [[UITextField alloc] initWithFrame:CGRectMake(5 * ScreenWidth , [UIScreen mainScreen].bounds.size.height - 40 * ScreenHeigth,  300 * ScreenWidth, 35 * ScreenHeigth)];
    self.comment.clearButtonMode = UITextFieldViewModeAlways;
    self.comment.clearsOnBeginEditing = YES;
    self.comment.layer.cornerRadius = 5 * ScreenWidth;
    self.comment.layer.masksToBounds = YES;
    self.comment.delegate = self;
    self.comment.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    self.comment.keyboardType = UIKeyboardTypeNamePhonePad;
    self.comment.textColor = [UIColor colorWithRed:100 / 255.0 green:100 / 255.0 blue:100 / 255.0 alpha:1.0];
    [self.view addSubview:self.comment];
    
    //发送
    self.send = [UIButton buttonWithType:UIButtonTypeCustom];
    self.send.layer.cornerRadius = 5 * ScreenWidth;
    self.send.layer.masksToBounds = YES;
    self.send.frame = CGRectMake(self.comment.frame.origin.x + self.comment.frame.size.width + 8 * ScreenWidth, self.comment.frame.origin.y, 90 * ScreenWidth, 35 * ScreenHeigth);
    [self.send setImage:[UIImage imageNamed:@"发送@2x.png"] forState:UIControlStateNormal];
    [self.send addTarget:self action:@selector(sendAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.send];
    

    
    
    
    
    //添加全屏右滑动手势
    id target = self.navigationController.interactivePopGestureRecognizer.delegate;
    // 创建全屏滑动手势，调用系统自带滑动手势的target的action方法
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
    // 设置手势代理，拦截手势触发
    pan.delegate = self;
    // 给导航控制器的view添加全屏滑动手势
    [self.view addGestureRecognizer:pan];
    // 禁止使用系统自带的滑动手势
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;

    
}

//发送按钮

- (void)sendAction:(UIButton *)sender
{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    NSDictionary *dict = @{@"content":self.comment.text, @"contentId":@"EF0B0bKUj0J64BZruk7", @"modelKey":@"article"};
    [manager POST:@"http://192.168.1.157:8080/api/center?userId=WWsQqAIdu8ofW5hOtvc&equipment=ios&requestType=Comment_Api&token=1802e52285ecf84d222b521f77b80cc5" parameters:dict success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        
        NSLog(@"%@", responseObject);
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
        
        NSLog(@"%@", error);
    }];

    
}

//分享按钮

- (void)right
{
    
}

//收藏按钮

- (void)likeAction:(UIButton *)sender
{
    
}

- (void)leftBarButtonAction:(UIBarButtonItem *)sender
{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
